Josh Dillon, Last Revised January 2022
This notebook examines an individual antenna's performance over a whole season. This notebook parses information from each nightly rtp_summarynotebook (as saved to .csvs) and builds a table describing antenna performance. It also reproduces per-antenna plots from each auto_metrics notebook pertinent to the specific antenna.
import os
from IPython.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
# If you want to run this notebook locally, copy the output of the next cell into the next line of this cell.
# antenna = "54"
# csv_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/_rtp_summary_'
# auto_metrics_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/auto_metrics_inspect'
# os.environ["ANTENNA"] = antenna
# os.environ["CSV_FOLDER"] = csv_folder
# os.environ["AUTO_METRICS_FOLDER"] = auto_metrics_folder
# Use environment variables to figure out path to the csvs and auto_metrics
antenna = os.environ["ANTENNA"]
csv_folder = os.environ["CSV_FOLDER"]
auto_metrics_folder = os.environ["AUTO_METRICS_FOLDER"]
print(f'antenna = "{antenna}"')
print(f'csv_folder = "{csv_folder}"')
print(f'auto_metrics_folder = "{auto_metrics_folder}"')
antenna = "207" csv_folder = "/home/obs/src/H5C_Notebooks/_rtp_summary_" auto_metrics_folder = "/home/obs/src/H5C_Notebooks/auto_metrics_inspect"
display(HTML(f'<h1 style=font-size:50px><u>Antenna {antenna} Report</u><p></p></h1>'))
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 1000)
import glob
import re
from hera_notebook_templates.utils import status_colors, Antenna
# load csvs and auto_metrics htmls in reverse chronological order
csvs = sorted(glob.glob(os.path.join(csv_folder, '*.csv')))[::-1]
print(f'Found {len(csvs)} csvs in {csv_folder}')
auto_metric_htmls = sorted(glob.glob(auto_metrics_folder + '/auto_metrics_inspect_*.html'))[::-1]
print(f'Found {len(auto_metric_htmls)} auto_metrics notebooks in {auto_metrics_folder}')
Found 255 csvs in /home/obs/src/H5C_Notebooks/_rtp_summary_ Found 233 auto_metrics notebooks in /home/obs/src/H5C_Notebooks/auto_metrics_inspect
# Per-season options
mean_round_modz_cut = 4
dead_cut = 0.4
crossed_cut = 0.0
def jd_to_summary_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/_rtp_summary_/rtp_summary_{jd}.html'
def jd_to_auto_metrics_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H5C_Notebooks/blob/main/auto_metrics_inspect/auto_metrics_inspect_{jd}.html'
this_antenna = None
jds = []
# parse information about antennas and nodes
for csv in csvs:
df = pd.read_csv(csv)
for n in range(len(df)):
# Add this day to the antenna
row = df.loc[n]
antnum = row['Ant']
if antnum != int(antenna):
continue
if this_antenna is None:
this_antenna = Antenna(row['Ant'], row['Node'])
jd = [int(s) for s in re.split('_|\.', csv) if s.isdigit()][-1]
jds.append(jd)
this_antenna.add_day(jd, row)
break
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~/anaconda/envs/RTP/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3360 try: -> 3361 return self._engine.get_loc(casted_key) 3362 except KeyError as err: ~/anaconda/envs/RTP/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc() ~/anaconda/envs/RTP/lib/python3.7/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item() KeyError: 'Ant' The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) /tmp/ipykernel_16984/3863632283.py in <module> 8 # Add this day to the antenna 9 row = df.loc[n] ---> 10 antnum = row['Ant'] 11 if antnum != int(antenna): 12 continue ~/anaconda/envs/RTP/lib/python3.7/site-packages/pandas/core/series.py in __getitem__(self, key) 940 941 elif key_is_scalar: --> 942 return self._get_value(key) 943 944 if is_hashable(key): ~/anaconda/envs/RTP/lib/python3.7/site-packages/pandas/core/series.py in _get_value(self, label, takeable) 1049 1050 # Similar to Index.get_value, but we do not fall back to positional -> 1051 loc = self.index.get_loc(label) 1052 return self.index._get_values_for_loc(self, loc, label) 1053 ~/anaconda/envs/RTP/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3361 return self._engine.get_loc(casted_key) 3362 except KeyError as err: -> 3363 raise KeyError(key) from err 3364 3365 if is_scalar(key) and isna(key) and not self.hasnans: KeyError: 'Ant'
# build dataframe
to_show = {'JDs': [f'<a href="{jd_to_summary_url(jd)}" target="_blank">{jd}</a>' for jd in jds]}
to_show['A Priori Status'] = [this_antenna.statuses[jd] for jd in jds]
df = pd.DataFrame(to_show)
# create bar chart columns for flagging percentages:
bar_cols = {}
bar_cols['Auto Metrics Flags'] = [this_antenna.auto_flags[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jee)'] = [this_antenna.dead_flags_Jee[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jnn)'] = [this_antenna.dead_flags_Jnn[jd] for jd in jds]
bar_cols['Crossed Fraction in Ant Metrics'] = [this_antenna.crossed_flags[jd] for jd in jds]
bar_cols['Flag Fraction Before Redcal'] = [this_antenna.flags_before_redcal[jd] for jd in jds]
bar_cols['Flagged By Redcal chi^2 Fraction'] = [this_antenna.redcal_flags[jd] for jd in jds]
for col in bar_cols:
df[col] = bar_cols[col]
z_score_cols = {}
z_score_cols['ee Shape Modified Z-Score'] = [this_antenna.ee_shape_zs[jd] for jd in jds]
z_score_cols['nn Shape Modified Z-Score'] = [this_antenna.nn_shape_zs[jd] for jd in jds]
z_score_cols['ee Power Modified Z-Score'] = [this_antenna.ee_power_zs[jd] for jd in jds]
z_score_cols['nn Power Modified Z-Score'] = [this_antenna.nn_power_zs[jd] for jd in jds]
z_score_cols['ee Temporal Variability Modified Z-Score'] = [this_antenna.ee_temp_var_zs[jd] for jd in jds]
z_score_cols['nn Temporal Variability Modified Z-Score'] = [this_antenna.nn_temp_var_zs[jd] for jd in jds]
z_score_cols['ee Temporal Discontinuties Modified Z-Score'] = [this_antenna.ee_temp_discon_zs[jd] for jd in jds]
z_score_cols['nn Temporal Discontinuties Modified Z-Score'] = [this_antenna.nn_temp_discon_zs[jd] for jd in jds]
for col in z_score_cols:
df[col] = z_score_cols[col]
ant_metrics_cols = {}
ant_metrics_cols['Average Dead Ant Metric (Jee)'] = [this_antenna.Jee_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Dead Ant Metric (Jnn)'] = [this_antenna.Jnn_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Crossed Ant Metric'] = [this_antenna.crossed_metrics[jd] for jd in jds]
for col in ant_metrics_cols:
df[col] = ant_metrics_cols[col]
redcal_cols = {}
redcal_cols['Median chi^2 Per Antenna (Jee)'] = [this_antenna.Jee_chisqs[jd] for jd in jds]
redcal_cols['Median chi^2 Per Antenna (Jnn)'] = [this_antenna.Jnn_chisqs[jd] for jd in jds]
for col in redcal_cols:
df[col] = redcal_cols[col]
# style dataframe
table = df.style.hide_index()\
.applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
.background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=list(z_score_cols.keys())) \
.background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=list(redcal_cols.keys())) \
.applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
.format({col: '{:,.4f}'.format for col in z_score_cols}) \
.format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
.format('{:,.2%}', na_rep='-', subset=list(bar_cols.keys())) \
.set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])
This table reproduces each night's row for this antenna from the RTP Summary notebooks. For more info on the columns, see those notebooks, linked in the JD column.
display(HTML(f'<h2>Antenna {antenna}, Node {this_antenna.node}:</h2>'))
HTML(table.render(render_links=True, escape=False))
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /tmp/ipykernel_16984/880101968.py in <module> ----> 1 display(HTML(f'<h2>Antenna {antenna}, Node {this_antenna.node}:</h2>')) 2 HTML(table.render(render_links=True, escape=False)) AttributeError: 'NoneType' object has no attribute 'node'
auto_metrics notebooks.¶htmls_to_display = []
for am_html in auto_metric_htmls:
html_to_display = ''
# read html into a list of lines
with open(am_html) as f:
lines = f.readlines()
# find section with this antenna's metric plots and add to html_to_display
jd = [int(s) for s in re.split('_|\.', am_html) if s.isdigit()][-1]
try:
section_start_line = lines.index(f'<h2>Antenna {antenna}: {jd}</h2>\n')
except ValueError:
continue
html_to_display += lines[section_start_line].replace(str(jd), f'<a href="{jd_to_auto_metrics_url(jd)}" target="_blank">{jd}</a>')
for line in lines[section_start_line + 1:]:
html_to_display += line
if '<hr' in line:
htmls_to_display.append(html_to_display)
break
These figures are reproduced from auto_metrics notebooks. For more info on the specific plots and metrics, see those notebooks (linked at the JD). The most recent 100 days (at most) are shown.
for i, html_to_display in enumerate(htmls_to_display):
if i == 100:
break
display(HTML(html_to_display))
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Power | 19.447477 | 12.939003 | 10.259814 | 19.447477 | 15.950122 | 13.794774 | 11.004666 | 13.466385 | 12.224021 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Discontinuties | 18.939743 | 11.419240 | 14.407464 | 12.372019 | 15.292130 | 12.651703 | 15.808400 | 17.790266 | 18.939743 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Discontinuties | 19.498215 | 13.843184 | 11.040640 | 15.875565 | 13.224244 | 18.964142 | 15.225631 | 19.498215 | 17.572774 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 19.683932 | 11.073093 | 9.099018 | 15.055782 | 12.362343 | 19.683932 | 15.675409 | 9.109954 | 8.129122 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 23.675416 | 11.555069 | 9.094335 | 18.284426 | 15.829319 | 23.675416 | 19.372021 | 8.097230 | 7.209955 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 21.246199 | 13.298959 | 10.973120 | 20.762723 | 17.824944 | 21.246199 | 17.699906 | 3.112719 | 2.428077 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 28.573640 | 17.516300 | 20.692002 | 16.724378 | 19.018280 | 24.404526 | 28.573640 | 6.728917 | 7.981260 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | nn Temporal Variability | 37.855343 | 23.522841 | 17.885940 | 26.497286 | 20.022465 | 37.855343 | 30.003718 | 19.902150 | 17.942743 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | nn Temporal Variability | 35.059770 | 17.428804 | 15.293754 | 24.470195 | 20.858462 | 35.059770 | 31.921647 | 8.310237 | 7.591773 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | nn Temporal Variability | 25.905366 | 14.803697 | 19.737071 | 17.225542 | 23.383307 | 20.698388 | 25.905366 | 8.122829 | 8.794044 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | nn Temporal Variability | 39.471240 | 20.977831 | 15.955783 | 28.060185 | 21.635889 | 39.471240 | 32.124613 | 13.915152 | 12.999110 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Power | 41.871665 | 12.075175 | 12.843809 | 40.560361 | 41.871665 | 34.320336 | 37.758620 | 4.403854 | 5.083691 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 41.977384 | 19.476895 | 18.117823 | 31.762263 | 31.385816 | 41.977384 | 36.226029 | 1.961403 | 1.288426 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 20.259830 | 15.093114 | 16.952768 | 8.416136 | 9.297127 | 16.691083 | 20.259830 | 4.244832 | 8.807294 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Shape | 15.717787 | 14.212363 | 15.717787 | 4.235319 | 4.742821 | 9.646678 | 11.367646 | 2.930906 | 6.438199 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Shape | 2.255449 | 2.255449 | 1.642361 | 0.998111 | 0.719582 | 0.112547 | 0.035707 | -2.068591 | -1.952926 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 19.395744 | 7.889864 | 10.109078 | 5.736839 | 7.183918 | 17.502236 | 19.395744 | 8.437075 | 12.230989 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 207 | N19 | RF_ok | ee Temporal Variability | 28.797349 | 9.512394 | 6.423398 | 7.927208 | 6.892906 | 28.797349 | 18.705239 | 20.296968 | 22.855083 |